#include "StdAfx.h"
#include "WarningPanelUI.h"

CWarningPanelUI::CWarningPanelUI(void): m_BackColor(UICOLOR_STANDARD_YELLOW)
{
}

CWarningPanelUI::~CWarningPanelUI(void)
{
}

LPCTSTR CWarningPanelUI::GetClass() const
{
	return _T("WarningPanelUI");
}

void CWarningPanelUI::SetWarningType(UINT uType)
{
	switch( uType ) {
   case MB_ICONERROR:
	   m_BackColor = UICOLOR_STANDARD_RED;
	   break;
   case MB_ICONWARNING:
	   m_BackColor = UICOLOR_STANDARD_YELLOW;
	   break;
   default:
	   m_BackColor = UICOLOR_WINDOW_BACKGROUND;
	   break;
	}
}

void CWarningPanelUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue)
{
	if( _tcscmp(pstrName, _T("type")) == 0 ) {
		if( _tcscmp(pstrValue, _T("error")) == 0 ) SetWarningType(MB_ICONERROR);
		if( _tcscmp(pstrValue, _T("warning")) == 0 ) SetWarningType(MB_ICONWARNING);
	}
	else CTextPanelUI::SetAttribute(pstrName, pstrValue);
}

SIZE CWarningPanelUI::EstimateSize(SIZE szAvailable)
{
	RECT rcText = { 0, 0, szAvailable.cx, szAvailable.cy };
	::InflateRect(&rcText, -6, -4);
	int nLinks = 0;
	CBlueRenderEngineUI::DoPaintPrettyText(m_pManager->GetPaintDC(), m_pManager, rcText, m_sText, 
		UICOLOR_EDIT_TEXT_NORMAL, UICOLOR__INVALID, NULL, nLinks, DT_WORDBREAK | DT_CALCRECT);
	return CStdSize(0, (rcText.bottom - rcText.top) + 16);
}

void CWarningPanelUI::DoPaint(HDC hDC, const RECT& rcPaint)
{
	RECT rcSign = m_rcItem;
	rcSign.bottom -= 8;
	CBlueRenderEngineUI::DoPaintFrame(hDC, m_pManager, rcSign, UICOLOR_STANDARD_GREY, UICOLOR_STANDARD_GREY, m_BackColor);
	RECT rcText = rcSign;
	::InflateRect(&rcText, -6, -4);
	m_nLinks = lengthof(m_rcLinks);
	CBlueRenderEngineUI::DoPaintPrettyText(hDC, m_pManager, rcText, m_sText, UICOLOR_BUTTON_TEXT_NORMAL, 
		UICOLOR__INVALID, m_rcLinks, m_nLinks, DT_WORDBREAK);
}
